<template>
  <view>
    <!-- 专辑背景 -->
    <view class="album_bg">
      <image mode="widthFix" :src="album.cover"></image>
      <view class="album_info">
        <view class="album_name">{{album.name}}</view>
        <view class="album_btn">关注专辑</view>
      </view>
    </view>
    <!-- 专辑作者 -->
    <view class="album_author">
      <view class="album_author_info">
        <image :src="album.user.avatar" mode="widthFix"></image>
        <view class="album_author_name">{{album.user.name}}</view>
      </view>
      <view class="album_author_desc">
        <text>{{album.desc}}</text>
      </view>
    </view>
    <!-- 列表 -->
    <view class="album_list">
      <view class="album_item" v-for="(item,index) in wallpaper" :key="item.id">
        <go-detail :list="wallpaper" :index="index">
          <image :src="item.thumb+item.rule.replace('$<Height>',360)" mode="aspectFill"></image>
        </go-detail>
      </view>
    </view>
  </view>
</template>

<script>
  import goDetail from "@/components/goDetail"
  export default {
    data() {
      return {
        params: {
          limit: 30,
          order: "new",
          skip: 0,
          /* 1 返回值中 有album对象
             0 返回值中只有 wallpaper数组
          */
          first: 1
        },
        album: {},
        wallpaper: [],
        hasMore: true,
      }
    },
    components: {
      goDetail
    },
    methods: {
      getList(options) {
        this.request({
          url: `https://service.picasso.adesk.com/v1/wallpaper/album/${options.id}/wallpaper`,
          // url: `https://service.picasso.adesk.com/v1/wallpaper/album/51ea274548d5b927eaaf5fa7/wallpaper`,
          data: this.params
        }).then(result => {
          // console.log(result.res)
          if (Object.keys(this.album).length === 0) {
            this.album = result.res.album
          }
          if (result.res.wallpaper.length === 0) {
            this.hasMore = false
            uni.showToast({
              title: "没有更多数据了！",
              icon: "none"
            })
            return
          }
          this.wallpaper = [...this.wallpaper, ...result.res.wallpaper]
          // console.log(JSON.stringify(result.res.album.desc))
          // console.log(this.wallpaper)
        })
      }
    },
    // 页面触底上拉加载下一页事件
    onReachBottom() {
      // console.log("上拉加载！")
      if (this.hasMore) {
        this.params.first = 0
        this.params.skip += this.params.limit
        this.getList()
      } else {
        uni.showToast({
          title: "我是有底线的。",
          icon: "none"
        })
      }
    },
    onLoad(options) {
      // console.log(options)
      this.getList(options)
    },
  }
</script>

<style lang="scss" scoped>
  .album_bg {
    position: relative;

    image {}

    .album_info {
      position: absolute;
      bottom: 0;
      width: 100%;
      left: 0;
      display: flex;
      justify-content: space-between;
      height: 80rpx;
      align-items: center;
      color: #fff;
      padding: 0 15rpx;

      .album_name {
        font-size: 40rpx;
      }

      .album_btn {
        background-color: $theme_font_color;
        width: 152rpx;
        height: 60rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 10rpx;
      }
    }

  }

  .album_author {
    padding: 10rpx;

    .album_author_info {
      padding: 10rpx 0;
      display: flex;

      image {
        width: 50rpx
      }

      .album_author_name {
        color: #000;
        margin-left: 15rpx;
      }
    }

    .album_author_desc {}
  }

  .album_list {
    display: flex;
    flex-wrap: wrap;


    .album_item {
      width: 33.33%;
      border: 3rpx solid #fff;

      image {
        height: 160rpx;
      }
    }
  }
</style>
